package
{
	import caurina.transitions.Tweener;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	import org.hamcrest.object.instanceOf;
	
	public class Menu extends Sprite
	{
		protected var shift:int = 20;
		protected var steps:int = 30;
		protected var fps:int = 60;
		protected var buttonWidth:Number = 200;
		protected var yAdjust:int = 150;
		protected var buttons:Array = new Array();
		protected var r:Render;
		protected var myTimer:Timer = new Timer(1000/fps); // 1 second
		public var showing:Boolean = false;
		protected var xmove:int=0,ymove:int=0;
		
		protected var start:int;
		protected var change:int;
		
		public function Menu()
		{
			cacheAsBitmap = true;
		}
		public function setPosition(x:int,y:int):void{
			xmove=x;
			ymove=y;
		}
		public function giveRender(render:Sprite):void{
			this.r=render as Render;
		}
		
		/**
		 * Adds a new button to the menu.
		 * @param str: Filepath to the button's image
		 * @param disable: Flag denoting if the button is disabled by default.
		 */
		public function add(str:String,disable:Boolean=false):Button{
			var b:Button = new Button(this);  
			b.setPosition(buttonWidth*(int(buttons.length/2)),(buttons.length%2)*-yAdjust);
			b.giveRenderSprite(r);
			b.overrideSize(buttonWidth,buttonWidth);
			b.load(this,str);
			if(disable){
				b.setClickable(false);
			}
			addChild(b);
			buttons.push(b);
			this.x=-buttonWidth*buttons.length/2;
			start=-buttonWidth*buttons.length/2;
			change=change-start;
			return b;
		}
		public function show():void{
			r.addChild(this);
			showing=true;
			this.y=ymove;
			Tweener.addTween(this,{x:shift+xmove,time: 1});
		}
		public function hide():void{
			showing=false;
			
			Tweener.addTween(this,{x:start+xmove,time: 1});
		}
		
	}
}